namespace Example
{
    using System;
    using System.Net;
    using Example.Properties;
    using SimpleWebServices.Net;
    using SimpleWebServices.Web;
    using SimpleWebServices.Web.UI.Html.Elements;
    using Xunit;

    public sealed class HomeFacts
    {
        private static readonly Resource _resource = new GenericResource
        {
            Location = "/home",
            Title = "Home Page",
            Links =
            {
                new Link { Relationship = "canonical", Hyperlink = new Uri("http://example.simplewebservices.org/home.en.html") }
            },
            Metadata =
            {
                new Meta { Name = "description", Content = "This is the home of the example website." },
                new Meta { Name = "DC.description", Content = "This is the home of the example website." }
            }
        }
        .ApplyDefaultValues<GenericResource>();

        [Fact]
        public void Get_LanguageNegotiation()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/home")
                .AcceptAnyContent()
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .IsLanguageNegotiationToEnglish()
                .HasNoCookies()
                .Result);
        }

        [Fact]
        public void Get_ContentNegotiation_html()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/home.en")
                .AcceptAnyContent()
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .IsContentNegotiationToTextHtml()
                .HasNoCookies()
                .Result);
        }

        [Fact]
        public void Get_ContentNegotiation_xhtml()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/home.en")
                .Accept("application/xhtml+xml")
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .IsSeeOther("http://example.simplewebservices.org/home.en.xhtml")
                .HasNoCookies()
                .Result);
        }

        [Fact]
        public void Get_HtmlRepresentation()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/home.en.html")
                .AcceptAnyContent()
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .Is(HttpStatusCode.OK)
                .HasCacheControlPublic()
                .WithExpires()
                .HasContentLanguageOfEnglish()
                .HasContentMD5()
                .ResponseIsTextHtml(_resource)
                .HasStyleSheetLink(Settings.Default.Stylesheet)
                .HasRobotsTag("FOLLOW,INDEX")
                .Evaluate<double>(1, Analytics.Xpath)
                .HasNoCookies()
                .HasContentLocation("http://example.simplewebservices.org/home.en.html")
                .Result);
        }

        [Fact]
        public void Get_XhtmlRepresentation()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/home.en.xhtml")
                .AcceptAnyContent()
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .Is(HttpStatusCode.OK)
                .HasCacheControlPublic()
                .WithExpires()
                .HasContentLanguageOfEnglish()
                .HasContentMD5()
                .ResponseIsApplicationXhtml(_resource)
                .HasStyleSheetLink(Settings.Default.Stylesheet)
                .HasRobotsTag("FOLLOW,INDEX")
                .Evaluate<double>(1, Analytics.Xpath)
                .HasNoCookies()
                .HasContentLocation("http://example.simplewebservices.org/home.en.xhtml")
                .Result);
        }
    }
}